﻿using System;
using System.Linq;
using System.Web.Security;
using pdtransport_v2._0.Models;

namespace pdtransport_v2._0.Areas.back
{
    public class CustomRoleProvider : RoleProvider
    {
        /// <summary>
        /// Ham su ly khi goi ham: FormsAuthentication.SetAuthCookie(account, true or false);
        /// </summary>
        /// <param name="username">account</param>
        /// <returns>tra ve quyen cua tai khoan</returns>
        public override string[] GetRolesForUser(string username)
        {
            pdtransportDataContext datacontext = new pdtransportDataContext();
            int sotk = 0;
            sotk = (from _tk in datacontext.TaiKhoans
                    where _tk.username == username
                    select _tk).Count();
            if (sotk != null)
            {
                TaiKhoan tk = (from _tk in datacontext.TaiKhoans
                               where _tk.username == username
                               select _tk).Single();
                return new String[] { tk.VaiTro }; 
            }
            else
                return new String[] { };
        }
        public override bool IsUserInRole(string username, string roleName)
        {
            throw new NotImplementedException();
        }
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
    
}